package com.itheima.tlias84.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tlias84.controller.po.InsertStuParam;
import com.itheima.tlias84.controller.po.SelectStuPageParam;
import com.itheima.tlias84.dao.mapper.StuMapper;
import com.itheima.tlias84.service.StuService;
import com.itheima.tlias84.service.dto.SelectStuDTO;
import com.itheima.tlias84.service.vo.PageVO;
import com.itheima.tlias84.utils.ResultUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class StuServiceImpl implements StuService {

    @Resource
    StuMapper stuMapper;

    @Override
    public ResultUtil selectStuByPage(SelectStuPageParam param) {
        Page<Object> page = PageHelper.startPage(param.getPage(), param.getPageSize());
        List<SelectStuDTO> list = stuMapper.selectPage(param);
        PageVO<Object> pageVO = new PageVO<>();
        pageVO.setTotal(page.getTotal());
        pageVO.setRows(list);
        return ResultUtil.success(pageVO);
    }

    @Override
    public SelectStuDTO selectStuById(Integer id) {
        return stuMapper.selectById(id);
    }

    @Override
    public int deleteStuById(List<Integer> ids) {
        return stuMapper.batchDelete(ids);
    }

    @Override
    public int insertStu(InsertStuParam param) {
        return stuMapper.insertOne(param);
    }

    @Override
    public int updateStu(InsertStuParam param) {
        return stuMapper.updateStu(param);
    }

    @Override
    public int stuViolation(Integer id, Integer score) {
        return stuMapper.violation(id, score);
    }
}
